/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CreateAppointmentPanel.java
 *
 * Created on Jul 12, 2011, 7:04:19 PM
 */
package panels;

import dao.AppointmentDao;
import dao.ClinicDao;
import java.util.logging.Level;
import java.util.logging.Logger;
import obj.Appointment;
import obj.Clinic;
import conn.EMIS4Connection;
import dao.LoginDao;
import dao.PersonDao;
import dao.PhoneDao;
import dao.SexDao;
import exec.NotFoundException;
import java.sql.SQLException;
import java.util.List;
import obj.Login;
import obj.Person;
import obj.Phone;
import obj.Sex;
import obj.Provider;
import util.LoggedInUser;

/**
 *
 * @author nknowles
 */
public class EditAppointmentPanel extends javax.swing.JPanel {

    private static EditAppointmentPanel instance;
    private Appointment appointment;
    private AppointmentDao appointmentDAO;
    private Clinic clinic;
    private ClinicDao clinicDAO;
    private List<Clinic> clinicList;
    private Login login;
    private LoginDao loginDAO;
    private int userID;
    private Person person;
    private PersonDao personDAO;
    private Phone phone;
    private PhoneDao phoneDAO;
    private List<Phone> phoneList;
    private Sex sex;
    private SexDao sexDAO;
    private List<Person> doctorList;
    private List<Provider> provider;
    private EMIS4Connection conn = EMIS4Connection.getInstance();
    private LoggedInUser loggedInUser = LoggedInUser.getInstance();

    public EditAppointmentPanel() {
        initComponents();


        appointment = new Appointment();
        appointmentDAO = new AppointmentDao();
        clinic = new Clinic();
        clinicDAO = new ClinicDao();
        login = new Login();
        loginDAO = new LoginDao();
        userID = loggedInUser.getUserID();
        initComponents();
        login = new Login();
        loginDAO = new LoginDao();
        person = new Person();
        personDAO = new PersonDao();
        phone = new Phone();
        phoneDAO = new PhoneDao();
        sex = new Sex();
        sexDAO = new SexDao();

        fillInformation();


        editDateTime();
    }

    public static EditAppointmentPanel getInstance() {
        if (instance == null) {
            instance = new EditAppointmentPanel();
        }
        return instance;
    }

    /** Creates new form CreateAppointmentPanel */
    private void fillInformation() {

        userID = loggedInUser.getUserID();
        phone.setPersonID(userID);

        conn.connect();
        try {
            // get objects from database

            login = loginDAO.getObject(conn.getConnection(), userID);
            person = personDAO.getObject(conn.getConnection(), userID);
            phoneList = phoneDAO.searchMatching(conn.getConnection(), phone);
            sex = sexDAO.getObject(conn.getConnection(), person.getSexID());
        } catch (NotFoundException ex) {
            Logger.getLogger(MemberInformationPanel.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(MemberInformationPanel.class.getName()).log(Level.SEVERE, null, ex);
        }

        // fill out info
        usernameLabel.setText(login.getUsername());
        fNameLabel.setText(person.getFirstName());
        lNameLabel.setText(person.getLastName());
        dobLabel.setText(person.getDOB().toString().substring(0, 10));
        ssnLabel.setText(convertSsnString(person.getSSN()));
        emailLabel.setText(person.getEmail());
        mariedStatusLabel.setText(person.getMaritalStatus());
        bloodTypeLabel.setText(person.getBloodType());
        doctorList = util.AppointmentUtil.fillDoctors(DoctorInTheHouse);
        if(insurance != null && provider != null)
            insurance.addItem(provider.listIterator());
        reasonField.setText(appointment.getVisitReason());
        symptomsField.setText(appointment.getSymptoms());
        medsField.setText(appointment.getCurrentMedications());
        //insurance.
        switch (phoneList.size()) {
            case 2:
                phone2Label.setText(convertPhoneString(phoneList.get(1).getNumber()));
            case 1:
                phone1Label.setText(convertPhoneString(phoneList.get(0).getNumber()));
        }
        sexLabel.setText(sex.getName());

    }

    private String convertSsnString(int ssn) {
        //error check to make sure values are correct
        StringBuilder sb = new StringBuilder(String.valueOf(ssn));
        sb.insert(3, '-');
        sb.insert(6, '-');
        return sb.toString();
    }

    private String convertPhoneString(String number) {
        StringBuilder sb = new StringBuilder(number);
        sb.insert(0, '(');
        sb.insert(4, ')');
        sb.insert(5, " ");
        sb.insert(9, '-');
        return sb.toString();
    }

    private void editDateTime() {
        String dt = util.DateUtils.currentDateTime();
        String time;
        int hour, min;
        int am = 0;

        yearComboBox.setSelectedItem(dt.substring(0, 4));
        monthComboBox.setSelectedIndex(Integer.valueOf(dt.substring(5, 7)) - 1);
        dayComboBox.setSelectedItem(dt.substring(8, 10));
        hour = Integer.valueOf(dt.substring(11, 13));
        if (hour >= 13) {
            am = 1;
            hour = hour % 12;
        } else if (hour == 0) {
            hour = 12;
        } else if (hour >= 12) {
            am = 1;
        }
        min = Integer.valueOf(dt.substring(14, 16));
        if (min > 30) {
            min = 0;
        } else {
            min = 3;
        }
        time = hour + ":" + min + "0";
        timeComboBox.setSelectedItem(time);
        ampmComboBox.setSelectedIndex(am);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        yearComboBox = new javax.swing.JComboBox();
        monthComboBox = new javax.swing.JComboBox();
        dayComboBox = new javax.swing.JComboBox();
        timeComboBox = new javax.swing.JComboBox();
        ampmComboBox = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        reasonField = new javax.swing.JTextArea();
        symptomsField = new javax.swing.JTextField();
        medsField = new javax.swing.JTextField();
        submitButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        DoctorInTheHouse = new javax.swing.JComboBox();
        CancelAppointment = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        PatientInfo = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        usernameLabel = new javax.swing.JLabel();
        fNameLabel = new javax.swing.JLabel();
        lNameLabel = new javax.swing.JLabel();
        dobLabel = new javax.swing.JLabel();
        ssnLabel = new javax.swing.JLabel();
        emailLabel = new javax.swing.JLabel();
        phone1Label = new javax.swing.JLabel();
        phone2Label = new javax.swing.JLabel();
        sexLabel = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        mariedStatusLabel = new javax.swing.JLabel();
        bloodTypeLabel = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        insurance = new javax.swing.JComboBox();
        Cancel = new javax.swing.JButton();
        btnPrintAppointment = new javax.swing.JButton();

        yearComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2011", "2012" }));
        yearComboBox.setName("yearComboBox"); // NOI18N
        yearComboBox.setNextFocusableComponent(monthComboBox);

        monthComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }));
        monthComboBox.setName("monthComboBox"); // NOI18N
        monthComboBox.setNextFocusableComponent(dayComboBox);

        dayComboBox.setName("dayComboBox"); // NOI18N
        dayComboBox.setNextFocusableComponent(timeComboBox);

        timeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "12:00", "12:30", "1:00", "1:30", "2:00", "2:30", "3:00", "3:30", "4:00", "4:30", "5:00", "5:30", "6:00", "6:30", "7:00", "7:30", "8:00", "8:30", "9:00", "9:30", "10:00", "10:30", "11:00", "11:30" }));
        timeComboBox.setName("timeComboBox"); // NOI18N
        timeComboBox.setNextFocusableComponent(ampmComboBox);

        ampmComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "AM", "PM" }));
        ampmComboBox.setName("ampmComboBox"); // NOI18N
        ampmComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ampmComboBoxActionPerformed(evt);
            }
        });

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        reasonField.setColumns(20);
        reasonField.setRows(5);
        reasonField.setName("reasonField"); // NOI18N
        reasonField.setNextFocusableComponent(symptomsField);
        jScrollPane1.setViewportView(reasonField);

        symptomsField.setFont(new java.awt.Font("Tahoma", 0, 12));
        symptomsField.setName("symptomsField"); // NOI18N
        symptomsField.setNextFocusableComponent(medsField);
        symptomsField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                symptomsFieldActionPerformed(evt);
            }
        });

        medsField.setFont(new java.awt.Font("Tahoma", 0, 12));
        medsField.setName("medsField"); // NOI18N
        medsField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                medsFieldActionPerformed(evt);
            }
        });

        submitButton.setText("Submit");
        submitButton.setName("submitButton"); // NOI18N
        submitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                submitButtonActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24));
        jLabel1.setText("Member Edit Appointment");
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel3.setText("Date:");
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel5.setText("Visit Reason:");
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel6.setText("Symptoms:");
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel7.setText("Doctor:");
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel11.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel11.setText("Medication:");
        jLabel11.setName("jLabel11"); // NOI18N

        DoctorInTheHouse.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        DoctorInTheHouse.setName("DoctorInTheHouse"); // NOI18N
        DoctorInTheHouse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DoctorInTheHouseActionPerformed(evt);
            }
        });

        CancelAppointment.setText("Cancel Appointment");
        CancelAppointment.setName("CancelAppointment"); // NOI18N
        CancelAppointment.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CancelAppointmentActionPerformed(evt);
            }
        });

        jPanel1.setName("jPanel1"); // NOI18N

        PatientInfo.setBackground(new java.awt.Color(220, 220, 210));
        PatientInfo.setName("PatientInfo"); // NOI18N
        PatientInfo.setLayout(new java.awt.GridBagLayout());

        jLabel8.setText("Email:");
        jLabel8.setName("jLabel8"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(10, 25, 0, 0);
        PatientInfo.add(jLabel8, gridBagConstraints);

        jLabel9.setText("SSN:");
        jLabel9.setName("jLabel9"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(10, 25, 0, 0);
        PatientInfo.add(jLabel9, gridBagConstraints);

        jLabel4.setText("DOB:");
        jLabel4.setName("jLabel4"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(10, 25, 0, 0);
        PatientInfo.add(jLabel4, gridBagConstraints);

        jLabel10.setText("Last Name:");
        jLabel10.setName("jLabel10"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(10, 25, 0, 0);
        PatientInfo.add(jLabel10, gridBagConstraints);

        jLabel12.setText("Sex:");
        jLabel12.setName("jLabel12"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(10, 25, 0, 0);
        PatientInfo.add(jLabel12, gridBagConstraints);

        jLabel2.setText("First Name:"); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(10, 25, 0, 0);
        PatientInfo.add(jLabel2, gridBagConstraints);

        jLabel13.setText("Phone1:");
        jLabel13.setName("jLabel13"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(10, 25, 0, 0);
        PatientInfo.add(jLabel13, gridBagConstraints);

        jLabel14.setText("Phone2:");
        jLabel14.setName("jLabel14"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(10, 25, 0, 0);
        PatientInfo.add(jLabel14, gridBagConstraints);

        usernameLabel.setName("usernameLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
        PatientInfo.add(usernameLabel, gridBagConstraints);

        fNameLabel.setName("fNameLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
        PatientInfo.add(fNameLabel, gridBagConstraints);

        lNameLabel.setName("lNameLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
        PatientInfo.add(lNameLabel, gridBagConstraints);

        dobLabel.setName("dobLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
        PatientInfo.add(dobLabel, gridBagConstraints);

        ssnLabel.setName("ssnLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
        PatientInfo.add(ssnLabel, gridBagConstraints);

        emailLabel.setName("emailLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
        PatientInfo.add(emailLabel, gridBagConstraints);

        phone1Label.setName("phone1Label"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
        PatientInfo.add(phone1Label, gridBagConstraints);

        phone2Label.setName("phone2Label"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
        PatientInfo.add(phone2Label, gridBagConstraints);

        sexLabel.setName("sexLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
        PatientInfo.add(sexLabel, gridBagConstraints);

        jLabel16.setText("User Name:");
        jLabel16.setName("jLabel16"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(10, 25, 0, 0);
        PatientInfo.add(jLabel16, gridBagConstraints);

        jLabel17.setText("Martial Status:");
        jLabel17.setName("jLabel17"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 10;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(10, 25, 0, 0);
        PatientInfo.add(jLabel17, gridBagConstraints);

        jLabel18.setText("Blood Type:");
        jLabel18.setName("jLabel18"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 11;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.weighty = 0.1;
        gridBagConstraints.insets = new java.awt.Insets(10, 25, 10, 0);
        PatientInfo.add(jLabel18, gridBagConstraints);

        mariedStatusLabel.setName("mariedStatusLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 10;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
        PatientInfo.add(mariedStatusLabel, gridBagConstraints);

        bloodTypeLabel.setName("bloodTypeLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 11;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.weightx = 0.1;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
        PatientInfo.add(bloodTypeLabel, gridBagConstraints);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(PatientInfo, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(PatientInfo, javax.swing.GroupLayout.PREFERRED_SIZE, 336, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        jLabel15.setText("Insurance");
        jLabel15.setName("jLabel15"); // NOI18N

        insurance.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        insurance.setName("insurance"); // NOI18N

        Cancel.setText("Cancel");
        Cancel.setName("Cancel"); // NOI18N
        Cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CancelActionPerformed(evt);
            }
        });

        btnPrintAppointment.setText("Print Appointment");
        btnPrintAppointment.setName("btnPrintAppointment"); // NOI18N
        btnPrintAppointment.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPrintAppointmentActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 322, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel11)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel7)
                                        .addGap(18, 18, 18)
                                        .addComponent(DoctorInTheHouse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(jLabel6)
                                                .addGap(45, 45, 45)))
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(symptomsField, javax.swing.GroupLayout.PREFERRED_SIZE, 451, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 451, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(medsField, javax.swing.GroupLayout.PREFERRED_SIZE, 451, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(36, 36, 36))))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(263, 263, 263)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(timeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(jLabel15)
                                            .addGap(18, 18, 18)
                                            .addComponent(insurance, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(jLabel3)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                            .addComponent(yearComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                .addGap(26, 26, 26)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(monthComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(32, 32, 32)
                                        .addComponent(dayComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(ampmComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(103, 103, 103)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addComponent(btnPrintAppointment)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(CancelAppointment)
                        .addGap(328, 328, 328)
                        .addComponent(submitButton)
                        .addGap(18, 18, 18)
                        .addComponent(Cancel)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(59, 59, 59)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel7)
                                    .addComponent(DoctorInTheHouse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel3)
                                    .addComponent(yearComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(monthComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(dayComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(timeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(ampmComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel15)
                                    .addComponent(insurance, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(28, 28, 28)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(jLabel6))
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(symptomsField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(jLabel11))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(4, 4, 4)
                                .addComponent(medsField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(submitButton)
                    .addComponent(Cancel)
                    .addComponent(btnPrintAppointment)
                    .addComponent(CancelAppointment))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_submitButtonActionPerformed
        // TODO add your handling code here:
        String date = util.AppointmentUtil.makeDateString(yearComboBox.getSelectedIndex(), monthComboBox.getSelectedIndex(), dayComboBox.getSelectedIndex(), timeComboBox.getSelectedIndex(), ampmComboBox.getSelectedIndex());
        System.out.println(date);
        appointment.setScheduledDate(util.AppointmentUtil.makeSqlDate(date.toString()));
        appointment.setDoctorID(doctorList.get(DoctorInTheHouse.getSelectedIndex()).getPersonID());
        appointment.setVisitReason(reasonField.getText());
        appointment.setSymptoms(symptomsField.getText());
        appointment.setCurrentMedications(medsField.getText());
        appointment.setAppointmentStatusID(5);
        try {
            conn.connect();
            appointmentDAO.create(conn.getConnection(), appointment);
        } catch (SQLException ex) {
            Logger.getLogger(CreateAppointmentPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_submitButtonActionPerformed

    private void ampmComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ampmComboBoxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ampmComboBoxActionPerformed

    private void CancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CancelActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_CancelActionPerformed

    private void medsFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_medsFieldActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_medsFieldActionPerformed

    private void CancelAppointmentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CancelAppointmentActionPerformed
        // TODO add your handling code here:
        appointment.setAppointmentStatusID(4);

    }//GEN-LAST:event_CancelAppointmentActionPerformed

    private void DoctorInTheHouseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DoctorInTheHouseActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_DoctorInTheHouseActionPerformed

    private void symptomsFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_symptomsFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_symptomsFieldActionPerformed

    private void btnPrintAppointmentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPrintAppointmentActionPerformed
      //  ReportUtil.generateReport(appointment);
    }//GEN-LAST:event_btnPrintAppointmentActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Cancel;
    private javax.swing.JButton CancelAppointment;
    private javax.swing.JComboBox DoctorInTheHouse;
    private javax.swing.JPanel PatientInfo;
    private javax.swing.JComboBox ampmComboBox;
    private javax.swing.JLabel bloodTypeLabel;
    private javax.swing.JButton btnPrintAppointment;
    private javax.swing.JComboBox dayComboBox;
    private javax.swing.JLabel dobLabel;
    private javax.swing.JLabel emailLabel;
    private javax.swing.JLabel fNameLabel;
    private javax.swing.JComboBox insurance;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lNameLabel;
    private javax.swing.JLabel mariedStatusLabel;
    private javax.swing.JTextField medsField;
    private javax.swing.JComboBox monthComboBox;
    private javax.swing.JLabel phone1Label;
    private javax.swing.JLabel phone2Label;
    private javax.swing.JTextArea reasonField;
    private javax.swing.JLabel sexLabel;
    private javax.swing.JLabel ssnLabel;
    private javax.swing.JButton submitButton;
    private javax.swing.JTextField symptomsField;
    private javax.swing.JComboBox timeComboBox;
    private javax.swing.JLabel usernameLabel;
    private javax.swing.JComboBox yearComboBox;
    // End of variables declaration//GEN-END:variables
}
